package com.cuzofu.fs.controller;

import com.cuzofu.fs.common.PageUtils;
import com.cuzofu.fs.common.R;
import com.cuzofu.fs.entity.IssueEntity;
import com.cuzofu.fs.po.IssuePO;
import com.cuzofu.fs.service.IssueService;
import com.cuzofu.fs.vo.IssueVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 审查意见信息
 *
 * @author cuzofu
 * @email cuzofu@qq.com
 * @date 2020-07-10 08:44:48
 */
@RestController
@RequestMapping("/issue")
public class IssueController {
    @Autowired
    private IssueService issueService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params) {
        PageUtils page = issueService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(IssuePO po) {
        List<IssueVO> list = issueService.queryList(po);

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
        IssueEntity issue = issueService.getById(id);

        return R.ok().put("issue", issue);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody IssueEntity issue) {
        issueService.save(issue);

        return R.ok();
    }

    /**
     * 保存(包括标注信息)
     */
    @RequestMapping("/create")
    public R save(@RequestBody IssueVO issue) {
        IssueEntity result = issueService.createIssue(issue);

        return R.ok().put("issue", result);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody IssueEntity issue) {
        issueService.updateById(issue);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids) {
        issueService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
